using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tool;

namespace SerialPortCommunicationProject
{
    public class StaticData
    {
        //Modbus Data Source
        public static List<FunctionCode> FunctionCodes = new List<FunctionCode>
        {
            new FunctionCode(){Code="01H",Meaning="读线圈寄存器"},
            new FunctionCode(){Code="02H",Meaning="读离散输入寄存器"},
            new FunctionCode(){Code="03H",Meaning="读保持寄存器"},
            new FunctionCode(){Code="04H",Meaning="读输入寄存器"},
            new FunctionCode(){Code="05H",Meaning="写单个线圈寄存器"},
            new FunctionCode(){Code="06H",Meaning="写单个保持寄存器"},
            new FunctionCode(){Code="0fH",Meaning="写多个线圈寄存器"},
            new FunctionCode(){Code="10H",Meaning="写多个保持寄存器"},
        };

        //serialPort and Socket(TCP) data source
        public List<CommunicationMode> CommModeList = new List<CommunicationMode>() {
                new CommunicationMode(){Name="串口", Mode=CommunicationModeEnum.SerialPort},
                new CommunicationMode(){Name="Socket(TCP)", Mode=CommunicationModeEnum.SocketTcp},
            };
        public static int[] BaudRates = new int[] { 600, 1200, 2400, 4800, 9600, 19200, 38400, 115200 };
        public static  int[] DataBits = new int[] { 5, 6, 7, 8 };
        public static List<ParityBits> ParityBitsList = new List<ParityBits>()
        {
            new ParityBits(){Name="None", Code=Parity.None},
            new ParityBits(){Name="Odd", Code=Parity.Odd},
            new ParityBits(){Name="Even", Code=Parity.Even},
            new ParityBits(){Name="Mark", Code=Parity.Mark},
            new ParityBits(){Name="Space", Code=Parity.Space},
        };
        public static List<StopBitsClass> StopBitsList = new List<StopBitsClass>()
        {
            new StopBitsClass(){Name="1", Code=StopBits.One},
            new StopBitsClass(){Name="1.5", Code=StopBits.OnePointFive},
            new StopBitsClass(){Name="2", Code=StopBits.Two}
        };
        public static string[] COrS = new string[] { "TCP Client", "TCP Server" };
        public static List<string> IpList = new List<string>()
            {
                //针对Server 获取本地主机IP
                //new System.Net.IPAddress( Dns.GetHostAddresses( Dns.GetHostName())[1].GetAddressBytes()).ToString() ,
                "127.0.0.1",
                "0.0.0.0"
            };
        public static readonly string DATABASENAME = "devicedebugtool";
        public static readonly string DEVICETABLENAME = "device";
        public static readonly string COMMANDTABLENAME = "command";

        public static readonly string SERIALPORT = "串口";
        public static readonly string SOCKETTCP = "Socket(TCP)";

        public static readonly string HEX = "HEX";
        public static readonly string ASCII = "ASCII";

        public static readonly string OPEN = "打开";
        public static readonly string CLOSE = "关闭";

        public static Device DefaultDeviceToAdd = new Device()
        { Name = "+", PortName="COM1", BaudRate = 9600, DataBits = 8, Parity = Parity.None, StopBits = StopBits.One, 
            Encoding = StaticData.ASCII, CommMode = StaticData.SERIALPORT, IsServer = false, 
            Commands = new ObservableCollection<Command>() { new Command() { Name = "双击添加" } }
        };
    }
}
